<template>
  <button v-if="!token" class="btn" plain  @click="getUserProfile" >
    <slot>

    </slot>
  </button>
  <block v-else >
    <slot></slot>
  </block>
</template>
<script lang='ts'  setup >
import { useUserStore } from '@/store'
import { storeToRefs } from 'pinia'

export interface IProps {
  cbFn: () => void
}

const props = defineProps<IProps>()
const userStore = useUserStore()
const {token } = storeToRefs(userStore)
const { login } = useUserStore()

 const getUserProfile = (e: any) => {
    uni.getUserProfile({
      desc: '用于登录',
      success: (res) => {
        login(res).then(() => {
          console.log('我出发了');
          
          props.cbFn()
        })
      }
    })
  }
 
</script>
<style lang='less' scoped >
.btn {
  background-color: transparent;
  padding: 0;
  margin: 0;
  position: static;
  border: 0 !important;
  border-radius: 0;
  color: transparent;
  width: 100%;
  height: 100%;
}
</style>